Haskell
Key Concepts
Saying what to compute rather than how
sum . map (^2) . filter even
Separating pure and inpure code:
Int -> Bool
vs Int -> IO Bool
Functions as first-class citizens:
map :: (a->b) -> [a] -> [b]
Equational reasoning
map f . map g
= map (f . g)
Main Drawbacks
- Difficult to reason about efficiency
- Limited tool support for developers
- Requires ability to think abstractly
Java
Key OO features
- Objects: This we create using new
- Classes: Specify what is in an object and what we can do to them
- Encapsulation (methods and data together: Put the methods which act on the data in the class
- Abstraction (and interfaces): Only worry about what methods do, not how they are implemented
- Data hiding (restrict access to data: Make data private and the 'interface' methods public
- Composition (stronger than aggregation): Objects can contain other objects - and use them to do the work
- Inheritance(specialisation, reuse, 'is-a': Reuse things like JButton and JLabel behaviour
- (Sub-type) Polymorphism (dynamic dispatch, late binding: Behaviour only known at runtime, also the reason that Lambdas can 'wrap up' a function
- Generics (parametric polymorphism): Implemented using sub-type polymorphism
Everything is an object in Java. State is usually mutable Prefer iteration as being more efficient